<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="diglogBg"></div>
<div class="diglogBox">
  <div class="closeBox">关闭窗口</div>
  <div id="amapMap" class="mapBox">
  </div>
</div>
<style type="text/css">
.diglogBg{position:fixed;width:100%;height:100%;top:0;left:0;background:rgba(0,0,0,0.5);z-index:99;}
.diglogBox{width:660px;height:400px;background:#fff;left:50%;top:50%;position:fixed;z-index:100;margin-top:-200px;margin-left:-330px;}
.closeBox{position:absolute;height:30px;background:#fff;font-size:14px;text-align:center;line-height:30px;top:-33px;right:0;z-index:101;padding:0 10px;cursor:pointer;}
.mapBox{width:100%;height:100%;}
</style>
<script>
  $(function(){
    $(".closeBox").on('click', function(){
      $(".diglogBg,.diglogBox").remove();
    });
  });
</script>
<script type="text/javascript">
$(function(){
    var map = new AMap.Map('amapMap',{
        zoom:15
    });

    var geocoder = new AMap.Geocoder();
    var marker = new AMap.Marker({
        map:map,
        bubble:true
    });

    var address = "<?php echo trim($_GET['area']);?>";

    AMap.plugin('AMap.Geocoder',function(){
        geocoder.getLocation(address,function(status,result){
            if(status=='complete'&&result.geocodes.length){
                marker.setPosition(result.geocodes[0].location);
                map.setCenter(marker.getPosition());
                $("#village_gps").val(result.geocodes[0].location);
            }
        });
    });

    AMap.event.addListener(map,'click',function(e){
        map.remove(marker);
        AMap.plugin('AMap.Geocoder',function(){
            var len=e.lnglat.getLng()+","+e.lnglat.getLat();
            marker = new AMap.Marker({
                position: len.split(","),
                map:map,
                bubble:true
            });
        });
        $("#village_gps").val(e.lnglat.getLng()+","+e.lnglat.getLat());
    });

});
</script>
